﻿using MediatR;
using Traceability.APP.Application.Command.Deepprocessings;
using Traceability.Damoin;
using Traceability.ErrorCode;
using Traceability.Infaseture;

namespace Traceability.APP.Application.CommandHadnLer.Deepprocessings
{
    public class GetDeepprocessingCommandHandLer : IRequestHandler<GetDeepprocessingCommand, APIResult<List<Deepprocessing>>>
    {

        private readonly IBaseRepostiy<Deepprocessing> _deepprocessing;

        public GetDeepprocessingCommandHandLer(IBaseRepostiy<Deepprocessing> deepprocessing)
        {
            _deepprocessing = deepprocessing;

        }
        public async Task<APIResult<List<Deepprocessing>>> Handle(GetDeepprocessingCommand request, CancellationToken cancellationToken)
        {
            // 获取所有养殖信息
            var list = _deepprocessing.GetAll().Where(x => !x.IsDeleted);

            // 根据批次筛选
            list = list.Where(x => x.Batch == request.Batch);

            return new APIResult<List<Deepprocessing>>
            {
                Code = ResultCode.Ok,
                Data = list.ToList(),
                Message = "获取成功"
            };
        }
    }
}
